package com.kmxd.ams.core.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import java.util.Arrays;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 类型:1aip包,2移交,3离线存储
 *
 * @author nickbi
 */
@Getter
@AllArgsConstructor
public enum AipTypeEnum {

  /** 形成 */
  AIP(1, "aip包"),
  /** 整理 */
  TRANSFER(2, "移交"),
  OFFLINE_STORAGE(3, "离线存储"),
  ;
  private Integer type;
  private String desc;

  public static AipTypeEnum convert(Integer type) {
    return Arrays.stream(values())
        .filter(x -> x.type.equals(type))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到aip包状态：" + type));
  }

  public static AipTypeEnum convert(String desc) {
    return Arrays.stream(values()).filter(x -> x.desc.equals(desc)).findAny().orElse(AIP);
  }

  @JsonCreator
  public static AipTypeEnum getValue(Integer type) {
    return Arrays.stream(values()).filter(x -> Objects.equals(x.type, type)).findAny().orElse(null);
  }
}
